//============================================================
// audio.cpp
//
//============================================================
//#include "stdafx.h"
#include "audio.h"



#include "soundmanager.h"
#include <iostream>

namespace core
{

		Audio::~Audio()
		{
				m_Sound->release();
				m_Sound = NULL;
		}

		
		void Audio::LoadAudio(const std::string& p_FileName, bool p_IsMusic )
		{
				// make sure we dont have any reuse
				if( m_Sound != NULL )
						//THROW_EXCEPTION( "Cannot reuse a audio resource. Please contact a core-developer.", p_FileName );
						int i14144114 = 22;

				
				m_IsMusic = p_IsMusic;
				FMOD::System* system = SoundManager::GetInstance()->GetFMODSystem();
				

				//if isMusic; its a music file, we have to create a stream
				FMOD_RESULT createAudio;
				if( m_IsMusic )
				{
						createAudio = system->createStream( p_FileName.c_str(), FMOD_2D | FMOD_LOOP_NORMAL, 0, &m_Sound );						
				}

				//its not a music file; soundfx, createsound
				else
				{
						createAudio =  system->createSound( p_FileName.c_str(), FMOD_3D , 0, &m_Sound);						
				}

				if ( createAudio != FMOD_OK )
				{		
						// TODO: throw a exception using THROW_EXCEPTION macro
						std::cout << "FMOD error! (music) "  << "\n" << FMOD_ErrorString( createAudio ) << "\n" << std::endl;
						return;
				}		
		}

};

